package com.seya.calculite.app;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Arumugam on 9/30/2014.
 */
public class DetailAdapter extends BaseAdapter {

    //private Details[] d;
    private List<Details> d;
    Context c;
    int listLayout;

    public DetailAdapter() {
    }

    public DetailAdapter(List<Details> d, Context c, int listLayout) {
        this.d = d;
        this.c = c;
        this. listLayout = listLayout;
    }

    @Override
    public int getCount() {
        return d.size();
    }

    @Override
    public Object getItem(int position) {
        return d.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater li = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = li.inflate(listLayout, parent, false);
        }

        TextView serial = (TextView)v.findViewById(R.id.serial);
        TextView vehicle = (TextView)v.findViewById(R.id.lstvehicle);
        TextView company = (TextView)v.findViewById(R.id.lstcompany);
        TextView tdate = (TextView)v.findViewById(R.id.lstdate);
        TextView start = (TextView)v.findViewById(R.id.lststart);
        TextView end = (TextView)v.findViewById(R.id.lstend);
        TextView km = (TextView)v.findViewById(R.id.lstkm);
        TextView tag = (TextView)v.findViewById(R.id.lsttag);
        TextView ttime = (TextView)v.findViewById(R.id.lsttime);

        serial.setText(Integer.toString(position+1));
        vehicle.setText(d.get(position).getVehicle());
        company.setText(d.get(position).getCompany());
        tdate.setText(d.get(position).getDatecreated());
        start.setText(d.get(position).getStartlocation());
        end.setText(d.get(position).getEndlocation());
        km.setText(d.get(position).getKm());
        tag.setText(d.get(position).getTag());
        ttime.setText(d.get(position).getTime());

        return v;
    }
}
